package jtk.project4.fleet.screen.addCustomer;

import java.sql.SQLException;

import nl.coderight.jazz.Controller;
import jtk.project4.fleet.FleetModel;
import jtk.project4.fleet.domain.Customers;
import jtk.project4.fleet.domain.Vendor;
import jtk.project4.fleet.event.AddCustomerEvent;
import jtk.project4.fleet.event.EquipmentEvent;
import jtk.project4.fleet.event.VendorEvent;
import jtk.project4.fleet.task.LoadCustomersTask;
import jtk.project4.fleet.task.LoadVendorTask;

public class AddCustomerController extends Controller {
	private FleetModel fleetModel;
	private AddCustomerView addCustomerView;
	
	public void handleEvent(AddCustomerEvent evt) throws SQLException {
		Customers customer = fleetModel.getCustomer();
		switch (evt.getType()) {
		case SAVE:
			//commit changes
			//fleetModel.insertCustomers(customer);
			fleetModel.insertOrUpdateCustomer(customer);
			executeTask(new LoadCustomersTask());
			break;
			
		default:
			propagateEvent(evt);
			break;
		}
	}


	@Override
	public void execute() {
		// TODO Auto-generated method stub
		fleetModel = (FleetModel) getModel();
		addCustomerView = new AddCustomerView();
		setView(addCustomerView);
		showView();
	}

}
